import Router from 'koa-router'
import axios from './utils/axios'

let router = new Router({prefix: '/categroy'})

const sign = `ebcf2f08dd01ccfc98cf04547e4ee0eb`
const serverUrl = `http://cp-tools.cn/categroy/`

router.get(`/crumbs`, async (ctx) => {
  let {status, data: {areas, types}} = await axios.get(`${serverUrl}crumbs`, {
    params: {
      city: ctx.query.city.replace('市', '') || `北京`,
      sign
    }
  })
  ctx.body = {
    areas: status === 200 ? areas : [],
    types: status === 200 ? types : []
  }
})

export default router
